
package kaizone.haining.chaobohui.setup;

import kaizone.haining.chaobohui.activity.DetailActivity;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;

public class Shareter {
    public static final int FALG_FX = 0x101;

    public static final int FALG_PL = 0x102;

    public static final int FALG_SC = 0x103;

    public static final int RESPONSE_COMPLETE = 1;

    public static final int RESPONSE_ERROR = 2;

    public static final int RESPONSE_IOEXCEPTION = 3;

    protected Handler mUiHandler;

    private Context mContext;

    public Shareter(Context context) {
        mUiHandler = new MyHandler();
        mContext = context;
    }

    public void sendMsgToUi(int type, int repsonsetype, String content) {
        Message msg = mUiHandler.obtainMessage();
        msg.arg1 = type;
        msg.arg2 = repsonsetype;
        mUiHandler.sendMessage(msg);
    }

    public class MyHandler extends Handler {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            int type = msg.arg1;
            int responseType = msg.arg2;
            String action = getActionString(type);
            if (responseType == RESPONSE_COMPLETE) {
                Toast.makeText(mContext, action + "完成", 400).show();
            } else if (responseType == RESPONSE_ERROR) {
                Toast.makeText(mContext, action + "失败", 400).show();
            } else if (responseType == RESPONSE_IOEXCEPTION) {
                Toast.makeText(mContext, "网络异常", 400).show();
            }
        }
    }

    public static String getActionString(int flag) {
        if (flag == XinLangWeiBo.FALG_FX) {
            return "分享";
        } else if (flag == XinLangWeiBo.FALG_PL) {
            return "评论";
        } else if (flag == XinLangWeiBo.FALG_SC) {
            return "收藏";
        } else {
            return "";
        }
    }

    public static class ShareEntry {

        public int flag;

        public String status;

        public String imageUrl;
    }

    public static ShareEntry edit(final String text, final String imageUrl) {
        ShareEntry entry = new ShareEntry();
        // final String status = text.substring(0, 100);
        entry.status = text;
        entry.imageUrl = imageUrl;
        return entry;
    }

    public static ShareEntry edit(final String title, final String content, final String imageUrl) {
        ShareEntry entry = new ShareEntry();
        int titleLen = title.length();
        final int end = 100 - titleLen;
        int contentLen = content.length();
        String text;
        if (contentLen < end) {
            text = content.substring(0, contentLen);
        } else {
            text = content.substring(0, end);
        }
        entry.status = title + "\t" + text;
        entry.imageUrl = imageUrl;
        return entry;
    }

    public static String editShareText(ShareEntry entry) {
        String text = null;
        if (entry.flag == DetailActivity.FLAG_NEWS) {
            text = "#潮博会app一手掌握海宁最潮活动#我正在使用潮博会app浏览潮博会新闻:" + entry.status
                    + ".小伙伴们快去围观! http://t.cn/z8NSWeg";
        }//
        else if (entry.flag == DetailActivity.FLAG_HUODONG) {
            text = "#海宁精彩活动尽在潮博会app#我在潮博会app中发现活动:" + entry.status + ".一起来看看吧! http://t.cn/z8NSWeg";

        }//
        else if (entry.flag == DetailActivity.FLAG_TUSHUO) {
            text = "#最美海宁，尽收潮博会app#，我在潮博会app中发现美图:" + entry.status
                    + ".一起来找找记忆中那些遗失的美好吧! http://t.cn/z8NSWeg";
        }
        return text;
    }
}
